#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>
#include <pthread.h>

void *myfunc(void *arg)
{
    int num = *(int *)arg;
    printf("%d\n", num);
    printf("child thread id: %lu\n", pthread_self());
    return NULL;
}

int main()
{
    const int len = 5;
    pthread_t pthid[5];
    int tmp[5] = {0, 0, 0, 0, 0};
    for (int i = 0; i < 5; ++i)
    {
        tmp[i] = i;
        int res = pthread_create(&pthid[i], NULL, myfunc, (void *)(tmp + i));
        if (res != 0)
        {
            printf("error number :%d\n", res);
            printf("%s\n", strerror(res));
        }
    }
    printf("parent thread id: %lu\n", pthread_self());

    for (int i = 0; i < 5; ++i)
    {
        printf("i = %d\n", i);
    }
    sleep(2);
}
